<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%-- 
<div data-dojo-type="dojo.data.ItemFileWriteStore" data-dojo-id="continentStore"
  data-dojo-props="url:'portal/part/data1.txt'"></div>
  
<div data-dojo-type="dijit.tree.ForestStoreModel" data-dojo-id="continentModel"
  data-dojo-props="store:continentStore, query:{type:'continent'},
  rootId:'root', rootLabel:'Continents', childrenAttrs:['children']"></div>

<!-- dndController:'dijit.tree.dndSource',拖拽 -->
<div data-dojo-type="dijit.Tree" id="mytree"
  data-dojo-props="model:continentModel, openOnClick:true" style="width:100%;height:100%">
  <script type="dojo/connect" data-dojo-event="onClick" data-dojo-args="item">
   			var tabs = dijit.byId("tabContainer");
			if(dijit.byId(continentStore.getValue(item, "id"))===undefined){
			  	// var closablePane = new dijit.layout.ContentPane({
				var closablePane = new dojox.layout.ContentPane({
			        title:continentStore.getLabel(item),
					id:continentStore.getValue(item, "id"),
			        closable: true,
			        href:continentStore.getValue(item, "href")+"?r="+new Date().getTime(),
			        onClose: function(){
			           // confirm() returns true or false, so return that.
			           // confirm("Do you really want to Close this?")
			           return true;
			        }
			    });
			    tabs.addChild(closablePane);
				tabs.selectChild(closablePane);
			}else{
				tabs.selectChild(dijit.byId(continentStore.getValue(item, "id")));
			}
		//alert("Execute of node :" + continentStore.getLabel(item)
        //+", population=" + continentStore.getValue(item, "population"));
  </script>
   <!-- /////////////////////// -->
</div>
--%>
<script type="text/javascript">
	//dojo.addOnLoad(function(){
  	//var tree = dijit.byId("mytree"); 
  	dojo.ready(function(){
    var store = new dojo.data.ItemFileReadStore({
        url: "portal/part/data1.txt"
    });
    var treeModel = new dijit.tree.ForestStoreModel({
        store: store,
        query: {"type": "continent"},
        rootId: "root",
        rootLabel: "Continents",
        childrenAttrs: ["children"]
    });
    var tree =  new dijit.Tree({
    	id:"mytree",
        model: treeModel
    }, "treeOne");
    tree.connect(tree, 'onClick', function(item){
			var tabs = dijit.byId("tabContainer");
			if(!(store.getValue(item, "href")===undefined)){
				if(dijit.byId(store.getValue(item, "id"))===undefined){
				  	// var closablePane = new dijit.layout.ContentPane({
					var closablePane = new dojox.layout.ContentPane({
				        title:store.getLabel(item),
						id:store.getValue(item, "id"),
				        closable: true,
				        href:store.getValue(item, "href")+"?r="+new Date().getTime(),
				        onClose: function(){
				           // confirm() returns true or false, so return that.
				           // confirm("Do you really want to Close this?")
				           return true;
				        }
				    });
				    tabs.addChild(closablePane);
					tabs.selectChild(closablePane);
				}else{
					tabs.selectChild(dijit.byId(store.getValue(item, "id")));
				}
			}
		});
  });
	</script>
   
 <div id="treeOne"></div>
	 
